﻿<UserControl x:Class="CBR.Views.DriveExplorerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Converters="clr-namespace:CBR.Components.Converters"
             xmlns:ViewModels="clr-namespace:CBR.ViewModels"
             xmlns:Selectors="clr-namespace:CBR.Components.Selectors"
             xmlns:Models="clr-namespace:CBR.Core.Models;assembly=CBR.Core"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>

        <!--Based treeview item style-->
        <Style x:Key="TreeItemItemStyle" TargetType="{x:Type TreeViewItem}">
            <Setter Property="Foreground" Value="{DynamicResource CbrForegroundBrush}" />
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <!--DRIVE treeview item style-->
        <Style x:Key="DriveItemStyle" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource TreeItemItemStyle}">
        </Style>

        <!--FOLDER treeview item style-->
        <Style x:Key="DirectoryItemStyle" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource TreeItemItemStyle}">
            <Setter Property="FontStyle" Value="Normal"/>
        </Style>

        <!--FILE treeview item style-->
        <Style x:Key="FileItemStyle" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource TreeItemItemStyle}">
            <Setter Property="FontStyle" Value="Normal"/>
        </Style>

        <!--treeview item style SELECTOR-->
        <Selectors:SysObjectItemStyleSelector x:Key="SysObjectItemStyleSelector"
            DriveStyle="{StaticResource DriveItemStyle}"
            DirectoryStyle="{StaticResource DirectoryItemStyle}" 
            FileStyle="{StaticResource FileItemStyle}" />

        <!--DRIVE treeview item template-->
        <HierarchicalDataTemplate DataType="{x:Type ViewModels:SysDriveViewModel}" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <Image Width="16" Height="16" Margin="3,0"
                       Source="{Binding Path=Type, Converter={x:Static Converters:TypeToImageConverter.Instance}}" />
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <!--FOLDER treeview item template-->
        <HierarchicalDataTemplate DataType="{x:Type ViewModels:SysDirectoryViewModel}" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <Image Width="16" Height="16" Margin="3,0"
                       Source="{Binding Path=Type, Converter={x:Static Converters:TypeToImageConverter.Instance}}" />
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <!--FILE treeview item template-->
        <DataTemplate DataType="{x:Type ViewModels:SysFileViewModel}">
            <StackPanel Orientation="Horizontal">
                <Image Width="16" Height="16" Margin="3,0" 
                       Source="{Binding Path=Type, Converter={x:Static Converters:TypeToImageConverter.Instance}}" />
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </DataTemplate>

    </UserControl.Resources>
    <Grid>
        <TreeView Name="FolderTree"
                  Background="{DynamicResource CbrDarkBackgroundBrush}"
                  ItemsSource="{Binding Drives}"
                  ItemContainerStyleSelector="{StaticResource SysObjectItemStyleSelector}"
                  SelectedValuePath="FullPath"
                  AllowDrop="True"
                  Drop="FolderTree_Drop"
                  DragOver="FolderTree_DragOver"
                  DragEnter="FolderTree_DragEnter" />
    </Grid>
</UserControl>
